#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib.request

def test_signal_and_image_analysis_apis():
    req = urllib.request.Request(url='http://127.0.0.1:5000/api/system_initialization', method='PUT')
    with urllib.request.urlopen(req) as f:
        print("status: /api/system_initialization")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/acquisition/7', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/acquisition/7")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=true&range=200&range=500', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=true&range=200&range=500")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=true&range=200&range=500', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=true&range=200&range=500")
        print(f.status)


    req = urllib.request.Request(url='http://127.0.0.1:5000/api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=false&range=500', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=false")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=false&range=500', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=false")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=true&range=200&range=500', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/rawdata/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH32&valid_data_only=true&range=200&range=500")
        print(f.status)


    req = urllib.request.Request(url='http://127.0.0.1:5000/api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=time_domain', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=time_domain")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=time_domain', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=time_domain")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=hilbert_envelope', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=hilbert_envelope")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=hilbert_envelope', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=hilbert_envelope")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=amplitude_frequency', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=amplitude_frequency")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=amplitude_frequency', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=amplitude_frequency")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=phase_frequency', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=US&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=phase_frequency")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=phase_frequency', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/spectrum/Rawdata_FPGA1_Frame0.bin?modality=PA&selected_channels=CH1&selected_channels=CH16&selected_channels=CH63&valid_data_only=true&range=100&range=1000&method=phase_frequency")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/reconstruction/Rawdata_FPGA1_Frame0.bin?modality=US&method=DAS&log_compress_parameter=16&sound_speed=1500&generate_crop_roi=true', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/reconstruction/Rawdata_FPGA1_Frame0.bin?modality=US&method=DAS&log_compress_parameter=16&sound_speed=1500&generate_crop_roi=true")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/reconstruction/Rawdata_FPGA1_Frame0.bin?modality=PA&method=DAS&log_compress_parameter=18&sound_speed=1500&generate_crop_roi=true', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/reconstruction/Rawdata_FPGA1_Frame0.bin?modality=PA&method=DAS&log_compress_parameter=18&sound_speed=1500&generate_crop_roi=true")
        print(f.status)


    req = urllib.request.Request(url='http://127.0.0.1:5000/api/reconstruction/paus_fusion/Rawdata_FPGA1_Frame0.bin?generate_crop_roi=true', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/reconstruction/paus_fusion/Rawdata_FPGA1_Frame0.bin?generate_crop_roi=true")
        print(f.status)


    req = urllib.request.Request(url='http://127.0.0.1:5000/api/reconstruction/paus_fusion/Rawdata_FPGA1_Frame0.bin?generate_crop_roi=false', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/reconstruction/paus_fusion/Rawdata_FPGA1_Frame0.bin?generate_crop_roi=false")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/simulation/compound_plane_wave', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/simulation/compound_plane_wave")
        print(f.status)


    req = urllib.request.Request(url='http://127.0.0.1:5000/api/simulation/compound_plane_wave', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/simulation/compound_plane_wave")
        print(f.status)

def test_full_waveform_inversion():
    req = urllib.request.Request(url='http://127.0.0.1:5000/api/simulation/full_waveform_inversion?anatomic_part_name=tibia&inversion_parameter=velocity', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/simulation/full_waveform_inversion?anatomic_part_name=tibia&inversion_parameter=velocity")
        print(f.status)


    req = urllib.request.Request(url='http://127.0.0.1:5000/api/simulation/full_waveform_inversion?anatomic_part_name=tibia_and_fibula&inversion_parameter=density', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/simulation/full_waveform_inversion?anatomic_part_name=tibia&inversion_parameter=density")
        print(f.status)

    req = urllib.request.Request(url='http://127.0.0.1:5000/api/simulation/full_waveform_inversion?anatomic_part_name=tibia_and_fibula&inversion_parameter=velocity', method='GET')
    with urllib.request.urlopen(req) as f:
        print("status: /api/simulation/full_waveform_inversion?anatomic_part_name=tibia&inversion_parameter=density")
        print(f.status)

if __name__ == '__main__': 
    print("API Test of image analysis API.")
    test_signal_and_image_analysis_apis()
    test_full_waveform_inversion()